<template>
	<el-dialog :visible.sync="dialog" :close-on-click-modal="false" :title="title" append-to-body width="600px"
	           @close="cancel">
	    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="82px">
	        <el-form-item label="专家回复" prop="answerContent">
	           <el-input type="textarea" v-model="form.answerContent" rows="9" :autosize="{ minRows: 9, maxRows: 12}"
	                     placeholder="回复内容,400字以内" style="width: 450px;"></el-input>
	        </el-form-item>
	    </el-form>
	    <div slot="footer" class="dialog-footer">
	        <el-button type="text" @click="cancel">取消</el-button>
	        <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
	    </div>
	</el-dialog>
</template>

<script>
	import { answerQue } from '@/api/course'
    export default {
        data() {
            return {
                loading: false,
                dialog: false,
                title: '专家答疑',
				isPublic:false,
                form: {pid:"", chapterId: "",chapterName:"",courseId:"",answerContent:"",type:null},
                rules: {
                    answerContent: [
                        {required: true, message: '请输入评价内容,400字以内',trigger: 'blur'}
                    ]
                }
            }
        },
        methods: {
            doSubmit() {
                this.$refs['form'].validate((valid) => {
                    if (valid) {
						if(this.form.answerContent.length>400){
							this.$message.error(`字数不能超多400字！`)
							return
						}
                        this.loading = true
                        answerQue(this.form).then(res => {
                            this.cancel()
							this.$parent.init()
                            this.$message.success(`回复成功！`)
                        }).catch(err => {
                            this.loading = false
                        })
                    } else {
                        return false
                    }
                })
            },
            cancel() {
                this.dialog = false
                this.loading = false
                this.$refs['form'].resetFields()
                this.form = {pid:"", chapterId: "",chapterName:"",courseId:"",answerContent:""}
            }
        }
    }
</script>

<style>
</style>